package com.kfm.dao;

import com.kfm.model.Student;
import com.kfm.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.util.List;

/**
 * 操作 student 数据表
 */
public class StudentDao {

    public List<Student> selectAll() throws Exception {
        QueryRunner queryRunner = DataSourceUtils.getQueryRunner();
        String sql = "select * from student";
        return queryRunner.query(sql, new BeanListHandler<Student>(Student.class));
    }

    public Student selectOne(int id) throws Exception {
        QueryRunner queryRunner = DataSourceUtils.getQueryRunner();
        String sql = "select * from student where id = ?";
        return queryRunner.query(sql, new BeanHandler<>(Student.class), id);
    }
}
